<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>登录并授权</title>
    <style>.error{color:red;}</style>
</head>
<body>

<div>使用你的Server帐号访问 [${client_id}] ，并同时登录Server</div>
<div class="error">${error}</div>
<form id="submitForm" action="<c:url value='/authorize'/>" method="post">
    <input type="hidden" name="response_type" value="${response_type}">
    <input type="hidden" name="client_id" value="${client_id}">
    <input type="hidden" name="redirect_uri" value="${redirect_uri}">
    <input type="hidden" name="state" value="${state}">
    <input type="hidden" id="scope" name="scope" value="">
    用户名：<input type="text" name="username" value="<shiro:principal/>"><br/>
    密&nbsp;&nbsp;码：<input type="password" name="password"><br/>
    <input type="checkbox" class="scope" value="/res/userInfo" checked="checked" readonly="readonly" disabled="disabled">基本信息<br/>
    <input type="checkbox" class="scope" value="/res/note">查看笔记<br/>
 	<button id="submitButton">登录并授权</button>
</form>
    <script type="text/javascript" src="<c:url value="/static/js/jquery-1.11.0.min.js"/>"></script>
    <script type="text/javascript">
    	var ctx = $("#ctx").val();
    	$("#submitButton").click(function(){
    		var scopes = "";
    		$("input.scope:checked").each(function(index, ele){
    			if(scopes){
    				scopes += " ";	//org.apache.oltu.oauth2.common.utils.OAuthUtils.decodeScopes(String)以空格作为分隔符
    			}
	    		scopes += $(ele).val();
    		});
    		$("#scope").val(scopes);
    		$("#submitForm").submit();
    		return ;
    	});
    </script>
</body>
</html>